package com.hospital.system.controller;

import com.hospital.common.domain.system.Doctor;
import com.hospital.common.exceptions.ServiceException;
import com.hospital.common.result.R;
import com.hospital.system.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：zhuzhujiang
 * @Description:
 * @name：DoctorController
 * @Date：2024/10/19 12:13
 */
@RestController
@RequestMapping("/doctor")
public class DoctorController {


    @Autowired
    private DoctorService doctorService;

    /***
     * 查询医生或者管理员信息
     */
    @PostMapping("/getDoctorInfo")
    public R<Doctor> getDoctorInfo(@RequestBody Doctor doctor){

        Doctor userResult = doctorService.getDoctorInfo(doctor);


        return R.success(userResult);
    }

    /**
     * 根据医生id查询医生对象
     */
    @GetMapping("/getDoctorInfoById/{doctorId}")
    public R<Doctor> getDoctorInfo(@PathVariable("doctorId") Long doctorId){

        Doctor doctor = doctorService.getById(doctorId);

        return R.success(doctor);
    }

    /**
     * 医生注册
     * @param doctor
     */
    @PostMapping("/doctor/doctorRegister")
    R doctorRegister(@RequestBody Doctor doctor){

        doctorService.doctorRegister(doctor);
        return R.success();
    }


    /**
     * 根据科室id查询医生信息
     * @param departmentId
     * @return
     */
    @GetMapping("findDoctor/{departmentId}")
    public R<List<Doctor>> findDoctor(@PathVariable("departmentId") Long departmentId){
        if(null==departmentId){
            throw new ServiceException("请选择科室");
        }
        List<Doctor> doctor = doctorService.findDoctor(departmentId);
        return R.success(doctor);
    }

}
